package com.oazon.common.util;

import android.content.Context;
import android.text.format.DateFormat;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class TimeUtils {
	public static String dateToWeek(int position) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

		Date currentDate = new Date();
		int b = currentDate.getDay();
		Date fdate;
		List<String> list = new ArrayList<String>();
		Long fTime = currentDate.getTime();
		for (int a = 0; a < 7; a++) {
			fdate = new Date();
			fdate.setTime(fTime + (a * 24 * 3600000));
			list.add(sdf.format(fdate));
		}
		return list.get(position);
	}

	/**
	 * @return
	 */
	public static String getCurrentTime() {
		return getFormatDateTime(new Date(), "yyyy月M日dd");
	}
	
	public static String getCurrentTimeSec() {
		return getFormatDateTime(new Date(), "yyyy-MM-dd HH:mm:ss");
	}

	public static String getFormatDateTime(Date date, String format) {
		SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.getDefault());
		return sdf.format(date);
	}

	public static String getLocalTime(Context context, String time) {

		String str_curTime = DateFormat.format("yyyy-MM-dd", new Date())
				.toString();
		int result = str_curTime
				.compareTo(time.substring(0, time.indexOf(" ")));
		if (result > 0) {
			return "昨天"
					+ time.substring(time.indexOf(" "), time.lastIndexOf(":"));
		} else if (result == 0) {
			return "今天"
					+ time.substring(time.indexOf(" "), time.lastIndexOf(":"));
		} else {
			return time;
		}
	}
}
